package com.study.lxy.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationConextHelper implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationConextHelper.applicationContext = applicationContext;
    }

    public static <T> T getBean(Class<T> claz){
        return applicationContext.getBean(claz);
    }

    public static Object getBean(String beanId){
        return applicationContext.getBean(beanId);
    }

    public static <T> T getBean(String beanId,Class<T> claz){
        return applicationContext.getBean(beanId,claz);
    }


}
